//
//  QKViewController.m
//  QKKit
//
//  Created by 1392984568@qq.com on 05/12/2018.
//  Copyright (c) 2018 1392984568@qq.com. All rights reserved.
//

#import "QKViewController.h"
#import "UIView+QKFrame.h"
#import "QKLoopBanner.h"
#import <QKKit/NSString+Hash.h>
#import <QKKit/RSACryptor.h>
#import <QKKit/SKEncryption.h>

@interface QKViewController () <QKLoopBannerDataSource,QKLoopBannerDelegate>
@property (nonatomic,assign)NSUInteger count;
@end

@implementation QKViewController

- (void)viewDidLoad
{
    self.count = 0;
    [self.view setBackgroundColor:[UIColor yellowColor]];
    
    
#if 0
    [super viewDidLoad];
    QKLoopBanner *loop = [[QKLoopBanner alloc] initWithFrame:CGRectMake(0, 100, 200, 200) loopSpace:5.f];
    [self.view addSubview:loop];
    [loop setBackgroundColor:[UIColor blackColor]];
    [loop setDelegate:self];
    [loop setDataSource:self];
    __weak typeof(loop)weekLoop = loop;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.count = 3;
        [weekLoop reloadData];
    });
#else
    
    //1.获取公钥
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"rsacert.der" ofType:nil];
    
    RSACryptor *cyptor = [[RSACryptor alloc] initWithPublicKey:"ddd" priviateKey:"aaa"];
    
    [cyptor loadPublicKey:filePath];
    
    //2.加载私钥 ，P12文件
    NSString *p12FilePath = [[NSBundle mainBundle]pathForResource:@"p.p12" ofType:nil];
    
    //password:生成p12文件时设置的密码
    [cyptor loadPrivateKey:p12FilePath password:@"123456"];
    
    
    NSData *result = [cyptor encryptData:[@"hello hjkk" dataUsingEncoding:NSUTF8StringEncoding]];
    
    
    //base64
    NSString *base64 = [result base64EncodedDataWithOptions:0];
    
    NSLog(@"%@",base64);
    
    
    
    //解密
    NSData *D_data = [cyptor decryptData:result];
    
    NSString *DString = [[NSString  alloc]initWithData:D_data encoding:NSUTF8StringEncoding];
    
    NSLog(@"解密的信息%@",DString);
    
#endif

}

- (UIPageControl *)pageControlOfloopBanner:(QKLoopBanner *)loopBanner
{
    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(loopBanner.bounds) - 30.f, CGRectGetWidth(loopBanner.bounds), 20.f)];
    return pageControl;
}

- (NSUInteger)numberOfImagesInLoopBanner:(QKLoopBanner *)loopBanner {
    return self.count;
}
- (void)loopBanner:(QKLoopBanner *)loopBanner reloadImageView:(UIImageView *)imageView index:(NSUInteger)index {
//    NSLog(@"index = %ld",index);
    NSString *imgeName = [NSString stringWithFormat:@"%lu.jpg",(unsigned long)index+1];
    [imageView setImage:[UIImage imageNamed:imgeName]];
}

- (void)loopBanner:(QKLoopBanner *)loopBanner chanedPage:(NSUInteger)page {
      NSLog(@"page = %ld",page);
}
- (void)loopBanner:(QKLoopBanner *)loopBanner didSelectedItem:(UIImageView *)imageView index:(NSUInteger)index {
    
}
@end
